import React from 'react'
import { Button, Checkbox, Form, Input } from 'antd';
import { LoginApi } from '../../api/user';
import {useNavigate} from 'react-router-dom'
function Index() {
  const nav=useNavigate()
  const onFinish = async(values) => {
    console.log('Success:', values);
    const res=await LoginApi(values)
    // console.log(res);
    localStorage.setItem('token',res.token)
    localStorage.setItem('userId',res.userId)
    localStorage.setItem('username',res.username)
    nav('/')
  };
  const onFinishFailed = errorInfo => {
    console.log('Failed:', errorInfo);
  };
  return (
    <div>
      <div style={{width:"100vw",height:"100vh",marginLeft:"350px",marginTop:"200px"}}>
      <div style={{marginLeft:"300px"}}>
        <p>react-ant-admin</p>
        <p>欢迎使用,请先登录</p>
      </div>
        <Form
          name="basic"
          labelCol={{ span: 8 }}
          wrapperCol={{ span: 16 }}
          style={{ maxWidth: 600 }}
          initialValues={{ remember: true }}
          onFinish={onFinish}
          onFinishFailed={onFinishFailed}
          autoComplete="off"
        >
          <Form.Item
            label="account"
            name="account"
            rules={[{ required: true, message: '请输入用户名' }]}
          >
            <Input />
          </Form.Item>

          <Form.Item
            label="Password"
            name="password"
            rules={[{ required: true, message: '请输入密码' }]}
          >
            <Input.Password />
          </Form.Item>

          <Form.Item name="remember" valuePropName="checked" label={null}>
            <Checkbox>记住我</Checkbox>
          </Form.Item>

          <Form.Item label={null}>
            <Button type="primary" htmlType="submit">
              登录
            </Button>
            <Button type="primary" style={{margin:"15px"}}>
              重置
            </Button>
          </Form.Item>
        </Form>
      </div>

    </div>
  )
}

export default Index
